package me.idashu.attg.controller;

import java.util.List;
import java.util.Locale;

import me.idashu.attg.domain.FeedBackEntity;
import me.idashu.attg.domain.PageEntity;
import me.idashu.attg.service.FeedbackService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/feedback")
public class FeedbackController {

	@Autowired
	public FeedbackService feedbackService;
	
	
	@RequestMapping("/getAllFeedbacks")
	public String feebacklist(Model model){
		PageEntity pageEntity = new PageEntity();
		selectFeedBacks(pageEntity, model);
		model.addAttribute("getFeedbacks", "意见反馈列表");
		return "feedbacklist";
	}
	
	@RequestMapping("/feedbackaAjaxList")
	public String feebackajaxlist(@ModelAttribute PageEntity pageEntity,Locale locale, Model model){
		selectFeedBacks(pageEntity, model);
		return "feedbackAjaxlist";
	}
	
	public void selectFeedBacks(PageEntity pageEntity,Model model){
		int count = feedbackService.findCountAllFeedBacks();
		pageEntity.setTotalPage(count);
		pageEntity.setPageLess(pageEntity.getPage());
		List<FeedBackEntity> feedBacks = feedbackService.findAllFeedBacks(pageEntity);
		if(feedBacks == null ||feedBacks.size() ==0){
			model.addAttribute("feedBacks",null);
		}else{
			model.addAttribute("feedBacks",feedBacks);
		}
		model.addAttribute("pageEntity",pageEntity);
	}
}
